{% extends "conversation_base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>我的消息</h2>
        <a href="{% url 'messaging:new_conversation' %}" class="btn btn-primary">
            <i class="bi bi-plus-circle"></i> 新对话
        </a>
    </div>

    <div class="list-group">
        {% for conv in conversations %}
        <a href="{% url 'messaging:conversation_detail' conv.id %}" 
           class="list-group-item list-group-item-action">
            <div class="d-flex justify-content-between">
                <div>
                    {% for user in conv.participants.all %}
                        {% if user != request.user %}
                            <strong>{{ user.username }}</strong>
                        {% endif %}
                    {% endfor %}
                    <p class="mb-0 text-muted">
                        {{ conv.messages.last.content|truncatechars:40 }}
                    </p>
                </div>
                <div class="text-end">
                    <small class="text-muted">
                        {{ conv.updated_at|timesince }}前
                    </small>
                    {% if conv.messages.filter(is_read=False, sender__ne=request.user).exists %}
                        <span class="badge bg-danger ms-2">未读</span>
                    {% endif %}
                </div>
            </div>
        </a>
        {% empty %}
        <div class="alert alert-info">暂无消息</div>
        {% endfor %}
    </div>
</div>
{% endblock %}